﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMP.ERP.Model;
using CMP.ERP.BLL;

namespace CMP.ERP.Admin.Controllers
{
    public class BrandController : Controller
    {
        //
        // GET: /Brand/
        //实例化CommodityTypeBLL对象
        CommodityTypeBLL bll = new CommodityTypeBLL();

        /// <summary>
        /// 显示数据信息
        /// </summary>
        /// <returns></returns>
        public ActionResult Brand_Show()
        {
            List<CommodityType> cc = bll.GetCommandTypeAll(); 
            return View(cc);
        }
        /// <summary>
        /// 实现详情功能
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Xiangqing(int id)
        {
            return View(bll.GetCommodityByCtid(id));
        }
        /// <summary>
        /// 实现添加功能
        /// </summary>
        /// <param name="ct"></param>
        /// <returns></returns>
        public ActionResult AddCommodityTypeDo(CommodityType ct)
        {
            if (bll.AddCommodityType(ct) > 0)
            {
                return Content("<script>alert('添加成功！'); location.href='/Brand/Brand_Show'</script>");
            }
            else
            {
                return Content("<script>alert('添加失败！'); location.href='/Brand/Brand_Show'</script>");
            }
        }
        /// <summary>
        /// 弹出修改视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id)
        {
            return View(bll.GetCtById(id));
        }
        /// <summary>
        /// 实现修改功能
        /// </summary>
        /// <param name="ct"></param>
        /// <returns></returns>
        public ActionResult EditCommodityTypeDo(CommodityType ct)
        {
            if (bll.EditCommodityType(ct) > 0)
            {
                return Content("<script>alert('更新成功！'); location.href='/Brand/Brand_Show'</script>");
            }
            else
            {
                return Content("<script>alert('更新失败！'); location.href='/Brand/Brand_Show'</script>");
            }
        }
        /// <summary>
        /// 实现删除功能
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult DelCommodityTypeDo(int id)
        {
            if (bll.DelCommodityType(id) > 0)
            {
                return Content("<script>alert('删除成功！'); location.href='/Brand/Brand_Show'</script>");
            }
            else
            {
                return Content("<script>alert('删除失败！'); location.href='/Brand/Brand_Show'</script>");
            }
        }
    }
}
